<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="true" name="HandheldFriendly">
    <title></title>
    <meta content="" name="keywords"/>
    <meta content="" name="description"/>
    <link href="/web/css/normalize.css" rel="stylesheet" type="text/css"/>
    <link href="/web/css/style.css" rel="stylesheet" type="text/css"/>
    <link href="/web/css/animate.css" rel="stylesheet" type="text/css"/>
    <link href="/web/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link href="/web/layui/css/layui.css" rel="stylesheet" type="text/css"/>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body>
<div id="app" v-cloak>
    <div class="contain">
        <div class="sidebar" id="head">

        </div>
        <section>
            <div class="right_h" id="right_h">

            </div>
            <div class="qulicklink">
                <ul>
                    <li><a href="javascript:;"></a></li>
                    <li><a href="javascript:;"><span>企业首页</span><img src="../web/images/close.png"></a></li>
                    <li class="dq"><a href="javascript:;"><span>业务管理</span><img src="../web/images/close.png"></a></li>
                    <li><a href="javascript:;"></a></li>
                </ul>
            </div>
            <div class="breadcrumbs">
                <ul>
                    <li>业务管理</li>
                    <li>发票管理</li>
                </ul>
            </div>
            <div class="clearfix"></div>
            <div class="content">
                <div class="addbtn">
                    <a @click="addbtnClick()" href="javascript:;" v-if="sum(48)">新增</a>
                </div>
                <div class="deletebtn">
                    <a @click="deletesClick()" href="javascript:;" v-if="sum(50)">删除</a>
                </div>
                <div class="importbtn">
                    <a @click="importClick()" href="javascript:;" v-if="sum(51)">导入</a>
                </div>
                <div class="search">
                    <!--模糊查询开始-->
                    <label>
                        <span>客户名称:</span>
                        <div class="searchbox">
                            <input @input="search($event)" placeholder="请输入您要搜索的客户名称" type="text">
                        </div>
                    </label>
                    <!--模糊查询结束-->

                </div>

                <!-- 这里是新增编辑弹出框开始-->
                <div class="consulting credit hidden">
                    <div class="addtitle">发票信息</div>
                    <div class="layerbody">
                        <label>
                            <span>合同编号:</span> <input :value="contractcode" @click="contractNum()" autocomplete="off"
                                                      name="resetTc" placeholder="合同编号" type="text"/>
                        </label>
                        <label>
                            <span>发票金额:</span> <input @input="invoicepricechange($event)" autocomplete="off" id="invoiceprice" name="resetTc"
                                                      placeholder="0.0"
                                                      type="number"/>
                        </label>
                        <label>
                            <span>订单金额:</span> <input :value="contractprice" autocomplete="off" name="resetTc"
                                                      placeholder="0.0"
                                                      readonly type="text" class="htmoneybg"/>
                        </label>
                        <label>
                            <span>开票时间:</span>
                            <div class="layui-input-inline">
                                <input autocomplete="off" class="layui-input" id="date1" name="resetTc"
                                       placeholder="yyyy-MM-dd" type="text">
                            </div>
                        </label>
                        <label>
                            <span>是否开票:</span>
                            <div class="layui-input-block">
                                <select autocomplete="off" class="type" id="ismake"
                                        lay-filter="batch" lay-search="required" lay-verify="required" name="resetTc"
                                        v-model="ismake">
                                    <option class="promptColor" value="">请选择是否开票</option>
                                    <option value="0">是</option>
                                    <option value="1">否</option>
                                </select>
                            </div>
                        </label>
                        <label>
                            <span>发票类型:</span>
                            <div class="layui-input-block">
                                <select autocomplete="off" class="type" id="paytypeid"
                                        lay-filter="batch" lay-search="required" lay-verify="required" name="resetTc"
                                        v-model="paytypeid">
                                    <option class="promptColor" value="0">请选择发票类型</option>
                                    <option :value="v.id" v-for="(v,index) in ajaxData.paytype">{{v.title}}</option>
                                </select>
                            </div>
                        </label>
                        <div class="address consultingbox">
                            <label>
                                <span>备注:</span>
                                <textarea autocomplete="off" class="contents" id="content" name="resetTc"
                                          placeholder="添加备注"
                                          resize="" rows="4"></textarea>
                            </label>
                        </div>
                    </div>
                    <button @click="addeditsureBtn()" class="surebtn" type="submit">确认</button>
                    <button @click="addresetBtn()" class="resetbtn" type="submit">重置</button>
                </div>
                <!-- 这里是新增编辑弹出框结束-->
                <!--点击合同编号出来的弹窗开始-->
                <div class="orderBox hidden">
                        <div class="search">
                            <!--模糊查询开始-->
                            <label>
                                <span>客户名称:</span>
                                <div class="searchbox">
                                    <input @input="searchWin($event,'archives','title')" placeholder="请输入您要搜索的客户名称"
                                           type="text"/>
                                </div>
                            </label>
                            <!--模糊查询结束-->
                        </div>
                        <div class="layerbody">
                        <ul class="itemList">
                            <li class="listBg">
                                <ol><input type="checkbox"/></ol>
                                <ol class="codenum">合同编号</ol>
                                <ol class="codenum">客户名称</ol>
                                <ol>订单金额</ol>
                                <ol>已收金额</ol>
                                <ol>未收金额</ol>
                            </li>
                            <li @dblclick="doubleClickEvent(v.id,v.code,v.contractprice)"
                                v-for="(v,index) in contractDataList">
                                <ol><input type="checkbox"/></ol>
                                <ol class="codenum">{{v.code}}</ol>
                                <ol class="codenum">{{v.title}}</ol>
                                <ol>{{v.contractprice}}</ol>
                                <ol>{{v.alreadyprice}}</ol>
                                <ol>{{v.contractprice - v.alreadyprice}}</ol>
                            </li>
                        </ul>
                    </div>
                </div>
                <!--点击合同编号出来的弹窗结束-->
            </div>
            <div class="t_body">
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                        <tr>
                            <th><input @click="deleteCheckAll()" class="checkboxAll" id="deleteCheckAll"
                                       type="checkbox"> 全选
                            </th>
                            <!--<th>客户名称</th>-->
                            <th>发票类型</th>
                            <th>发票金额</th>
                            <!--<th>开票人</th>-->
                            <th>开票日期</th>
                            <th>是否开票</th>
                            <th>录入时间</th>
                            <!--<th>录入人</th>-->
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr @dblclick="editorClick(v.id)" v-for="(v,index) in tableDataList">
                            <td><input :id="'listcheck' + (v.id)" class="selectCheck" type="checkbox"></td>
                            <!--                        <td>{{v.customer}}</td>-->
                            <td>{{v.invoicetypetitle}}</td>
                            <td>{{v.invoiceprice}}</td>
                            <!--                        <td>{{v.makeuser}}</td>-->
                            <td>{{v.maketime}}</td>
                            <td style="color: rgb(49, 195, 122);" v-if="v.ismake == 1">是</td>
                            <td style="color: rgb(255, 0, 0);" v-else>否</td>
                            <td>{{v.createtime}}</td>
                            <!--                        <td>{{v.createuser}}</td>-->
                            <td>
                                <!--                            <div class="view">-->
                                <!--                                <a @click="viewClick()" href="javascript:;">-->
                                <!--                                    <img src="images/view.png">-->
                                <!--                                </a>-->
                                <!--                                <span>查看</span>-->
                                <!--                            </div>-->
                                <div class="editor" v-if="sum(49)">
                                    <a @click="editorClick(v.id)" href="javascript:;">
                                        <img src="images/editor.png">
                                    </a>
                                    <span>编辑</span>
                                </div>
                                <div class="deletes" v-if="sum(50)">
                                    <a @click="deletesClick(v.id)" href="javascript:;">
                                        <img src="images/deletes.png">
                                    </a>
                                    <span>删除</span>
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <!---------------------------分页start----------------------------->
                <div class="pageFen" v-if="totalNum>1">
                    <ul>
                        <li>
                            <a @click="setPage(curNum-1)" class="pageLink" href="#">上一页</a>
                        </li>
                        <li v-for="n in totalNum">
                            <a class="pageLink curNum" v-if="n == curNum" v-text="n"></a>
                            <a @click="setPage(n)" class="pageLink" href="javascript:;" v-else v-text="n"></a>
                        </li>
                        <li><a @click="setPage(curNum+1)" class="pageLink" href="#">下一页</a></li>
                    </ul>
                </div>
                <!---------------------------分页end-------------------------------->
            </div>
        </section>
    </div>
</div>
<script src="/web/js/vue.js"></script>
<script src="/web/js/jquery-1.10.0.min.js"></script>
<script src="/web/layui/layui.js"></script>
<script src="/web/js/transform.js"></script>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //录入时间
        laydate.render({
            elem: '#date1', //指定元素
            type: "date", // 组件的类型：year,month,time···
            format: 'yyyy-MM-dd'// 设置显示格式
        });
        //最后跟进时间
        laydate.render({
            elem: '#date2', //指定元素
            type: "date", // 组件的类型：year,month,time···
            format: 'yyyy-MM-dd'// 设置显示格式
        });
        //最后跟进时间
        laydate.render({
            elem: '#date3', //指定元素
            type: "date", // 组件的类型：year,month,time···
            format: 'yyyy-MM-dd'// 设置显示格式
        });
    });
</script>
<script>
    layui.use('element', function () {
        var element = layui.element;
    });
</script>
<script>
    AppData = new Vue({
        el: '#app',
        data: {
            tableData: {},
            categoryIndex: 0,
            show: false,
            tableDataList: {},
            contractDataList: {},
            ajaxData: '',
            totalNum: 0, //总页数
            listRows: 8, //每页数量
            curNum: 1, //当前页码
            departmentList: {},
            dataList: {},
            map: {},
            contractid: 0,
            contractcode: '',
            contractprice: '',
            paytpeid: 0,
            addoredit: 0,
            ismake: 0,
            paytypeid: 0,
            addoredit: 0,
            mylay: '',
            characterid: 2
        },
        mounted() {
            $("#head").load("header.html");
            $("#right_h").load("right.html");
            this.getIndexData();
        },
        methods: {
            verification(data) {
                if (data.status == 2) {
                    layer.msg(data.message, {icon: 2, time: 1000}, function () {
                        window.location.href = "login.html";
                    });
                }
            },
            addbtnClick() {
                this.addresetBtn();
                this.addoredit = 0;
                layeraddoredit = layer.open({
                    type: 1,
                    title: '新开发票',
                    maxmin: true,
                    resize: true,
                    shadeClose: false, //点击遮罩关闭层
                    scrollbar: true,
                    area: ['850px', '630px'],
                    content: $('.consulting'),
                    success: function () {
                        $.ajax({
                            type: "GET",
                            dataType: "json",
                            url: '/invoice/create',
                            data: {},
                            success: function (data) {
                                AppData.verification(data);
                                AppData.ajaxData = data;
                                console.log(data);
                            },
                            error: function (msg) {
                                console.log(msg);
                            }
                        });
                    },
                    end: function () { //解决弹窗关闭以后,弹窗内容还出现在下方的问题
                        $('.consulting').hide();
                    }
                })
            },
            addeditsureBtn() {
                var data = {
                    contractid: this.contractid,
                    invoicetypeid: this.paytypeid,
                    invoiceprice: $('#invoiceprice').val(),
                    maketime: $('#date1').val(),
                    ismake: $('#ismake').val(),
                    content: $('#content').val()
                };
                if (this.addoredit == 0) {
                    //新增
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: '/invoice',
                        data: data,
                        success: function (data) {
                            AppData.verification(data);
                            if (data.status == 1) {
                                layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                    AppData.getIndexData();
                                    layer.close(layeraddoredit);
                                });
                            } else {
                                layer.msg(data.message, {icon: 2, time: 1000});
                            }
                        },
                        error: function (msg) {
                        }
                    });
                } else {
                    //编辑
                    $.ajax({
                        type: "PUT",
                        dataType: "json",
                        url: '/invoice/' + this.addoredit,
                        data: data,
                        success: function (data) {
                            AppData.verification(data);
                            if (data.status == 1) {
                                layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                    AppData.getIndexData();
                                    layer.close(layeraddoredit);
                                });
                            } else {
                                layer.msg(data.message, {icon: 2, time: 1000});
                            }
                        },
                        error: function (msg) {
                        }
                    });
                }
            },
            setPage(num) {
                //页码小于等于1
                if (num < 1) {
                    num = 1;
                }
                //页码大于总页数
                if (num > this.totalNum) {
                    num = this.totalNum;
                }
                //页码赋给当前页
                this.curNum = num;
                this.getIndexData();
            },
            search(e) {
                var that = this;
                var keywords = e.target.value;
                this.map.title = keywords;
                this.getIndexData();
            },
            searchWin(e, table, field) {//客户列表搜索名称
                var that = this;
                var keywords = e.target.value;
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '/keyword',
                    data: {'table': table, 'field': field, 'keywords': keywords},
                    success: function (data) {
                        AppData.archivesList = data.list;
                    },
                    error: function (msg) {
                        console.log(msg);
                    }
                });
            },
            sum(sumid) {//验证列表里的修改删除是否要显示(根据对应的id)
                for (i in this.dataList) {
                    if (sumid == this.dataList[i].id) {
                        return true;
                    }
                }
                return false;
            },
            editorClick(edid) {
                this.addoredit = edid;
                layeraddoredit = layeraddoredit = layer.open({
                    type: 1,
                    title: '编辑发票',
                    maxmin: true,
                    resize: true,
                    shadeClose: false, //点击遮罩关闭层
                    scrollbar: true,
                    area: ['850px', '630px'],
                    content: $('.consulting'),
                    success: function () {
                        $.ajax({
                            type: "GET",
                            dataType: "json",
                            url: '/invoice/' + edid,
                            data: {},
                            success: function (data) {
                                AppData.verification(data);
                                AppData.ajaxData = data;
                                console.log(data);
                                //输入框赋值
                                // var date = new Date(data.info.maketime * 1000);
                                AppData.contractcode = data.info.code;
                                AppData.contractid = data.info.contractid;
                                AppData.ismake = data.info.ismake;
                                AppData.paytypeid = data.info.invoicetypeid;
                                AppData.contractprice = data.info.contractprice;
                                $('#date1').val(data.info.maketime);
                                $('#content').val(data.info.content);
                                $('#invoiceprice').val(data.info.invoiceprice);
                            },
                            error: function (msg) {
                            }
                        });
                    },
                    end: function () { //解决弹窗关闭以后,弹窗内容还出现在下方的问题
                        $('.consulting').hide();
                    }
                })
            },
            deletesClick(deleteid) {
                layui.use('layer', function () {
                    layer.confirm('确认要删除吗？', {
                        btn: ['确定', '取消']//按钮
                    }, function () {
                        let ids = [];
                        if (deleteid) {
                            //单个删除
                            ids.push(deleteid);
                        } else {
                            //全部删除
                            let checkBoxs = AppData.tableDataList;
                            for (let i in checkBoxs) {
                                if ($('#listcheck' + checkBoxs[i].id).is(":checked")) {
                                    ids.push(checkBoxs[i].id);
                                }
                            }
                        }
                        if (ids.length == 0) {
                            layer.msg('请选择你要删除的选项');
                            return false;
                        }
                        $.ajax({
                            type: "DELETE",
                            dataType: "json",
                            url: '/invoice/0',
                            data: {'ids': ids},
                            success: function (data) {
                                AppData.verification(data);
                                if (data.status == 1) {
                                    layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                        //重新加载列表
                                        AppData.getIndexData();
                                    });
                                } else {
                                    layer.msg(data.message, {icon: 2, time: 1000});
                                }
                            },
                            error: function (msg) {
                            }
                        });
                    });
                });
            },
            deleteCheckAll() {
                let checkBoxs = AppData.tableDataList;
                if ($('#deleteCheckAll').is(":checked")) {
                    for (let j in checkBoxs) {
                        $('#listcheck' + checkBoxs[j].id).prop('checked', true);
                    }
                } else {
                    for (let j in checkBoxs) {
                        $('#listcheck' + checkBoxs[j].id).prop('checked', false);
                    }
                }
            },
            resetbtnClick() {
                $('input[name="resetval"]').val('');
                $('select[name="resetval"]').val('');
            },
            addresetBtn() {
                $('input[name="resetTc"]').val('');
                $('select[name="resetTc"]').val('');
                $('textarea[name="resetTc"]').val('');
                this.contractcode = '';
                this.ismake = 0;
                this.contractprice = '';
                this.paytypeid = 0;
            },
            contractNum() {
                this.mylay = parent.layer.open({
                    type: 1,
                    title: '合同列表',
                    maxmin: true,
                    resize: true,
                    shadeClose: false, //点击遮罩关闭层
                    area: ['750px', '550px'],
                    id: 'layer02',
                    content: $('.orderBox'),
                    success: function () {
                        $.ajax({
                            type: "GET",
                            dataType: "json",
                            url: '/contract',
                            data: {},
                            success: function (data) {
                                console.log(data);
                                AppData.contractDataList = data.list.data;
                            },
                            error: function (msg) {
                            }
                        });
                    },
                    end: function () { //解决弹窗关闭以后,弹窗内容还出现在下方的问题
                        $('.orderBox').hide();
                    }
                })
            },
            doubleClickEvent(id, code, price) {//获取订单名称的双击事件
                this.contractid = id;
                this.contractcode = code;
                this.contractprice = price;
                layer.close(this.mylay);
            },
            searchWin(e, table, field) {//客户列表搜索名称
                var that = this;
                var keywords = e.target.value;
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '/keyword',
                    data: {'table': table, 'field': field, 'keywords': keywords},
                    success: function (data) {
                        AppData.contractDataList = data.list;
                    },
                    error: function (msg) {
                        console.log(msg);
                    }
                });
            },
            invoicepricechange(e){
                var price = e.target.value;
                if (eval(price) > eval(this.contractprice)){
                    $('#invoiceprice').val(this.contractprice);
                }
            },
            getIndexData() {
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '/invoice',
                    data: {listRows: this.listRows, page: this.curNum, map:this.map},
                    success: function (data) {
                        AppData.verification(data);
                        console.log(data);
                        AppData.totalNum = data.list.last_page;  //获取总的页面数
                        AppData.dataList = data.userInfo.jurisdiction; //所有的权限
                        AppData.ajaxData = data;
                        let dataS = data.userInfo.jurisdiction;//后台初始数据
                        var dataArr = [];
                        for (let i in dataS) {
                            dataArr.push(dataS[i]); //属性
                        }
                        /*调用封装的改变数据结构方法*/
                        let tableData = setTreeData(dataArr);
                        let tableDataObj = {...tableData};//把转换后的数组通过扩展运算符改成对象便于遍历
                        AppData.tableData = tableDataObj;
                        //表格中数据的渲染
                        let tableList = {...data.list.data};
                        //转换时间戳为具体的年月日
                        // let dataObj = data.list.data;
                        // for (let i in dataObj) {
                        //     var dataObj1 = dataObj[i].maketime;
                        //     var date = new Date(dataObj1 * 1000);
                        //     dataObj[i].maketime = date.getFullYear() + '-' + (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-' + date.getDate() + ' ';
                        //     var dataObj2 = dataObj[i].createtime;
                        //     var date = new Date(dataObj2 * 1000);
                        //     dataObj[i].createtime = date.getFullYear() + '-' + (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-' + date.getDate() + ' ';
                        // }
                        AppData.tableDataList = tableList;
                    },
                    error: function (msg) {
                    }
                });
            },
        }
    })
</script>
</body>
</html>
